<!-- 案例详情 -->
<template>
    <div>
        <case-detail :case-info="caseInfo" class="cp-container"></case-detail>
        <!-- 评论 -->
        <div class="cp-container" style="background-color: #fff; padding: 20px; margin-top: 20px;">
            <comment-view comment-type="CASES" :comment-id="$route.params.cs"></comment-view>
        </div>
    </div>
</template>

<script lang="ts">
import {
    Vue,
    Component
} from 'nuxt-property-decorator'
import caseDetail from '~/components/shop/caseDetail.vue'
import commentView from '~/components/common/commentView.vue'
import {getCaseInfo} from '~/api/shop'
@Component({
    layout: 'shop',
    components: {
        caseDetail,
        commentView
    },
    head () {
        const vthis = this as any
        return {
            title: `${vthis.caseInfo.exampleName}-案例-CIIP供需中心`,
            meta: [
                {
                    hid: 'description',
                    name: 'description',
                    content: `${vthis.exampleName}-案例-CIIP供需中心`
                }
            ]
        }
    },
    validate ({params, store}) {
        const flag: boolean = /^\d+$/.test(params.id) && /^\d+$/.test(params.cs)
        if (flag) {
            store.commit('setShopId', params.id)
        }
        return flag
    },
    async asyncData ({params, error}) {
        const {data}: any = await getCaseInfo(params.cs)
        let caseInfo: any = {}
        if (data.code >= 0) {
            caseInfo = data.data
        } else {
            error({statusCode: 500, message: data.msg})
        }
        return {
            caseInfo
        }
    }
})
export default class PageCaseDetail extends Vue {
    caseInfo: any = {}
}
</script>
